package com.asp.alumnisystem.utils;

import android.graphics.Color;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;

import com.asp.alumnisystem.R;
import com.asp.alumnisystem.app.App;


/**
 * 静态Toast
 */
public class ToastUtil {

	private static Toast toast;
	private static TextView view;

	private static void initToast(){
		toast = new Toast(App.getAppContext());
		view = new TextView(App.getAppContext());
		view.setTextColor(Color.WHITE);
		view.setBackgroundResource(R.drawable.black_circular_view);
		view.setGravity(Gravity.CENTER);
		int size = (int) view.getTextSize();
		view.setPadding(size,size,size,size);
		toast.setView(view);
        toast.setGravity(Gravity.CENTER, 0, 0);
	}

	/**
	 * 显示短时间Toast
	 * @param txt 显示内容
     */
	public static void showShortToast(String txt) {
		if (StringUtils.isNull(txt)) {
			return;
		}
		if (toast == null) {
			initToast();
		}
		toast.setDuration(Toast.LENGTH_SHORT);
		view.setText(txt);
		toast.show();
	}

	/**
	 * 显示长时间Toast
	 * @param txt 显示内容
	 */
	public static void showLongToast(String txt) {
		if (StringUtils.isNull(txt)) {
			return;
		}
		if (toast == null) {
			initToast();
		}
		toast.setDuration(Toast.LENGTH_LONG);
		view.setText(txt);
		toast.show();
	}

	/** 取消显示 */
	public static void hideToast() {
		if (null != toast) {
			toast.cancel();
		}
	}

}